﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Activities.Presentation;
using System.Activities.Presentation.View;
using System.Globalization;
using System.Activities.Presentation.Model;
using System.Activities;
using Microsoft.VisualBasic.Activities;

namespace MyData.Activities.Designers
{
  //Used to convert ModelItem.Value to a string for <Binding Path="ModelItem.Value.Expression" Converter="{StaticResource objectConverter}"/>
  [ValueConversion(typeof(object), typeof(String))]
  public class ObjectConverter : IValueConverter
  {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
      //ModelItem.Source.ComputedValue ...
      ModelItem mi = value as ModelItem;
      VisualBasicValue<Object> computedValue = mi.Source.ComputedValue as VisualBasicValue<Object>;
      return computedValue.ExpressionText;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
      throw new Exception("The method or operation is not implemented.");
    }
  }

  // Interaction logic for QueryDesigner.xaml
  public partial class QueryDesigner
  {
    public QueryDesigner()
    {
      InitializeComponent();
    }

    private void ExpressionTextBox_GotFocus(object sender, RoutedEventArgs e)
    {
      RaiseEvent(new RoutedEventArgs(ActivityDesigner.GotFocusEvent, (sender as ExpressionTextBox)));
    }
  }
}
